// Type Aliases 与联合类型、交叉类型
// 这里，type ShapeDetails定义了一个联合类型，可以是Circle或Square类型，展示了type在定义复杂类型组合时的优势。
export type Shape = "circle" | "square";
export type Circle = {
  kind: "circle";
  radius: number;
};

export type Square = {
  kind: "square";
  sideLength: number;
};

export type ShapeDetails = Circle | Square;

export function getArea(shape: ShapeDetails) {
  if (shape.kind === "circle") {
    return Math.PI * shape.radius ** 2;
  } else {
    return shape.sideLength ** 2;
  }
}

console.log(getArea({ kind: "circle", radius: 5 }));
